<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button class="set">创建(存储)</button>
</body>
<script>

  var setBtn = document.querySelector(".set");

  // cookie的创建
  // 1. cookie 的存取都依赖于 document.cookie 
  // 2. cookie也是以键值对形式存在的(key=value  键名键值都是字符串)
  // 3. cookie是一条一条存储的

  // cookie的时效性  => cookie可以设置过期时间
  // 默认情况下 cookie在会话结束(浏览器关闭)时过期,如果想设置过期时间,需要借助expires属性
  // expires可以接收一个字符串类型的时间(世界时) 当做过期时间  

  setBtn.onclick = function () {
    var user = "a123123";
    var pwd = "123123";
    var phone = "17386141517";
    var email = "1272071495@qq.com";

    var date = new Date();
    date.setDate(date.getDate() + 7);

    document.cookie = "user=" + user + ";expires=" + date.toUTCString();
    document.cookie = "pwd=" + pwd + ";expires=" + date.toUTCString();
    document.cookie = "phone=" + phone + ";expires=" + date.toUTCString();
    document.cookie = "email=" + email + ";expires=" + date.toUTCString();
  }



</script>

</html>